import React, {Component} from 'react';
import {BrowserRouter, Route, Switch, Redirect} from 'react-router-dom'
import Home from './pages/Home'
import About from './pages/About'
import MyNavLink from './components/MyNavLink'
import Header from "./components/Header";

// import './bootstrap.css';

class App extends Component {
  render() {
    return (
      <div>
        {/*一劳永逸，不要在这里引入Router，在RenderDOM里面写(<XXXRouter><App/></XXXRouter>)*/}
        <BrowserRouter>
          <Header/>
          <div className="row">
            <div className="col-xs-2 col-xs-offset-2">
              <div className="list-group">
                {/*编写路由链接*/}
                {/*<Link className="list-group-item" to="/about">About</Link>
                <Link className="list-group-item" to="/home">Home</Link>*/}
                {/*Link不会追加active类名，要想动态设置active，使用NavLink*/}
                {/*<NavLink activeClassName="active" className="list-group-item" to="/about">About</NavLink>
                <NavLink activeClassName="active" className="list-group-item" to="/home">Home</NavLink>*/}
                {/* 自封装NavLink */}
                <MyNavLink to='/about/test'><h2>About</h2></MyNavLink>
                <MyNavLink to='/home'>Home</MyNavLink>
              </div>
            </div>
            <div className="col-xs-6">
              <div className="panel">
                <div className="panel-body">
                  {/*注册路由*/}
                  {/*通过Switch实现单一路由规则匹配，找到了一个匹配就不再往下查找*/}
                  <Switch>
                    <Route path="/about" component={About}/>
                    {/*exact 开启严格匹配，默认是模糊匹配(Link可以多给/home/a/b), 不太建议随意开严格匹配*/}
                    {/*<Route path="/home" exact={true} component={Home}/>*/}
                    <Route path="/home"  component={Home}/>
                    <Redirect to="/home"/>
                  </Switch>
                </div>
              </div>
            </div>
          </div>
        </BrowserRouter>
      </div>
    );
  }
}

export default App;
